package com.onstar.cn.weight;

import android.app.Dialog;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;


public class ResetCodeLayout extends LinearLayout {
	private CustomButton btn_reset_code;
	private CustomButton btn_cancel;
	private CustomButton btn_send_email;
	private View view;
	private Dialog popDialog;

	public ResetCodeLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context);
		initView();
	}

	public ResetCodeLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView();
	}

	public ResetCodeLayout(Context context) {
		super(context);
		initView();
	}

	private void initView() {
		view = inflate(getContext(), R.layout.weight_joinme_reset_code_alert_dialog, this);
		btn_reset_code = (CustomButton) view.findViewById(R.id.btn_reset_code);
		btn_send_email = (CustomButton) view.findViewById(R.id.btn_send_email);
		btn_cancel = (CustomButton) view.findViewById(R.id.btn_cancel);

		btn_cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				colse();
			}
		});
	}

	public void show(boolean isEmail) {
		if (isEmail) {
			btn_send_email.setVisibility(View.INVISIBLE);
		} else {
			btn_send_email.setVisibility(View.VISIBLE);
		}
		popDialog = new Dialog(getContext(), R.style.alert_dialog);
		Window window = popDialog.getWindow();
		window.setWindowAnimations(R.style.share_layout_animation);
		LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		window.setGravity(Gravity.BOTTOM);
		popDialog.addContentView(view, params);
		popDialog.show();
	}

	public void colse() {
		if (popDialog != null) {
			popDialog.dismiss();
		}
	}

	public void setOnClickListener(OnClickListener onClickListener) {
		btn_reset_code.setOnClickListener(onClickListener);
	}

	public void setOnSendEmailClickListener(OnClickListener onClickListener) {
		if (btn_send_email.getVisibility() == View.VISIBLE) {
			btn_send_email.setOnClickListener(onClickListener);
		}
	}
}
